/*   1:    */ package tt.dz.web.controller.job;
/*   2:    */ 
/*   3:    */ import com.alibaba.fastjson.JSON;
/*   4:    */ import java.util.Date;
/*   5:    */ import java.util.HashMap;
/*   6:    */ import java.util.List;
/*   7:    */ import java.util.Map;
/*   8:    */ import javax.annotation.Resource;
/*   9:    */ import javax.servlet.http.HttpServletRequest;
/*  10:    */ import org.apache.commons.lang.StringUtils;
/*  11:    */ import org.springframework.stereotype.Controller;
/*  12:    */ import org.springframework.web.bind.annotation.RequestMapping;
/*  13:    */ import org.springframework.web.bind.annotation.ResponseBody;
/*  14:    */ import tt.dz.biz.service.Job.JobLockService;
/*  15:    */ import tt.dz.biz.service.common.CommonService;
/*  16:    */ import tt.dz.biz.task.DailyDealTask;
import tt.dz.common.DzConstants;
/*  17:    */ import tt.dz.common.DzConstants.sysJob;
/*  18:    */ import tt.dz.common.LogUtil;
/*  19:    */ import tt.dz.vo.JobLockVO;
/*  20:    */ import tt.dz.web.controller.BaseController;
/*  21:    */ 
/*  22:    */ @Controller
/*  23:    */ public class JobManageController
/*  24:    */   extends BaseController
/*  25:    */ {
/*  26:    */   @Resource(name="jobLockService")
/*  27:    */   private JobLockService jobLockService;
/*  28:    */   @Resource(name="commonService")
/*  29:    */   private CommonService commonService;
/*  30:    */   
/*  31:    */   @ResponseBody
/*  32:    */   @RequestMapping(value={"/listAllJob"}, produces={"application/json;charset=UTF-8"})
/*  33:    */   public String listAllJob()
/*  34:    */   {
/*  35: 45 */     Map responseModle = new HashMap();
/*  36:    */     try
/*  37:    */     {
/*  38: 47 */       List<JobLockVO> jobList = this.jobLockService.listAllDailyJob();
/*  39: 48 */       String sysState = this.jobLockService.querySysCurrentState();
/*  40: 49 */       Date accountingDate = this.commonService.getAccountingDate();
/*  41: 50 */       responseModle.put("requestStatus", "success");
/*  42: 51 */       responseModle.put("requestResult", jobList);
/*  43: 52 */       responseModle.put("sysState", sysState);
/*  44: 53 */       responseModle.put("accountingDate", accountingDate);
/*  45:    */     }
/*  46:    */     catch (Exception e)
/*  47:    */     {
/*  48: 55 */       LogUtil.error("查询所有job异常", e);
/*  49: 56 */       responseModle.put("requestStatus", "error");
/*  50:    */     }
/*  51: 58 */     return JSON.toJSONString(responseModle);
/*  52:    */   }
/*  53:    */   
/*  54:    */   @ResponseBody
/*  55:    */   @RequestMapping(value={"/exeJob"}, produces={"application/json;charset=UTF-8"})
/*  56:    */   public String exeTask(HttpServletRequest request)
/*  57:    */   {
/*  58: 64 */     Map<String, String> rs = new HashMap();
/*  59:    */     try
/*  60:    */     {
/*  61: 66 */       String taskName = request.getParameter("taskName");
/*  62: 67 */       String runState = request.getParameter("runState");
/*  63: 68 */       if (StringUtils.isBlank(taskName))
/*  64:    */       {
/*  65: 69 */         rs.put("requestStatus", "error");
/*  66: 70 */         rs.put("errorMsg", "执行的任务名称（taskName）不能为空！");
/*  67: 71 */         return JSON.toJSONString(rs);
/*  68:    */       }
/*  69: 73 */       String sysState = this.jobLockService.querySysCurrentState();
/*  70: 74 */       if (!StringUtils.equals(runState, sysState))
/*  71:    */       {
/*  72: 75 */         rs.put("requestStatus", "error");
/*  73: 76 */         rs.put("errorMsg", "执行任务的前置系统状态与当前系统状态不一致，不能执行该任务！");
/*  74: 77 */         return JSON.toJSONString(rs);
/*  75:    */       }
/*  76: 81 */       if (StringUtils.equals(taskName, "changeDayTask")) {
/*  77: 82 */         changeDayTask();
/*  78: 83 */       } else if (StringUtils.equals(taskName, "dailyAccountTask")) {
/*  79: 84 */         dealDailyTask();
/*  80: 85 */       } else if (StringUtils.equals(taskName, "calcBalanceTask")) {
/*  81: 86 */         calccheckTask();
/*  82:    */       }
/*  83: 88 */       rs.put("requestStatus", "success");
/*  84: 89 */       return JSON.toJSONString(rs);
/*  85:    */     }
/*  86:    */     catch (Exception e)
/*  87:    */     {
/*  88: 91 */       rs.put("requestStatus", "error");
/*  89: 92 */       rs.put("errorMsg", "执行任务异常！");
/*  90:    */     }
/*  91: 93 */     return JSON.toJSONString(rs);
/*  92:    */   }
/*  93:    */   
/*  94:    */   private void changeDayTask()
/*  95:    */     throws Exception
/*  96:    */   {
/*  97:104 */     DailyDealTask changeDayTask = new DailyDealTask(DzConstants.sysJob.CHANGE_DAY_TASK.value());
/*  98:105 */     changeDayTask.executeTask();
/*  99:106 */     dealDailyTask();
/* 100:    */   }
/* 101:    */   
/* 102:    */   private void dealDailyTask()
/* 103:    */     throws Exception
/* 104:    */   {
/* 105:113 */     DailyDealTask dailyAccountTask = new DailyDealTask(DzConstants.sysJob.DAILY_ACCOUNT_TASK.value());
/* 106:114 */     dailyAccountTask.executeTask();
/* 107:115 */     calccheckTask();
/* 108:    */   }
/* 109:    */   
/* 110:    */   private void calccheckTask()
/* 111:    */     throws Exception
/* 112:    */   {
/* 113:123 */     DailyDealTask calcBalTask = new DailyDealTask(DzConstants.sysJob.CALC_BALANCE_TASK.value());
/* 114:124 */     calcBalTask.executeTask();
/* 115:    */   }
/* 116:    */ }


/* Location:           F:\work\pengyu\mainServer\WEB-INF\classes\
 * Qualified Name:     tt.dz.web.controller.job.JobManageController
 * JD-Core Version:    0.7.0.1
 */